//
//  HMMainTabBar.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/9.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMMainTabBar.h"

@implementation HMMainTabBar

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        self.backgroundImage = [UIImage imageNamed:@"tabbar_background"];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    int mainTabBarBtnCount = 5;
    
    CGFloat width = self.frame.size.width/mainTabBarBtnCount;
    CGFloat height = self.frame.size.height;
    
    int index = 0;
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            view.frame = CGRectMake(index*width, 0, width, height);
            index += index==1 ? 2 : 1;
        }
        
    }
    
    UIButton *addBtn = [[UIButton alloc] init];
    [self addSubview:addBtn];
    addBtn.frame = CGRectMake(mainTabBarBtnCount/2*width, 0, width, height);
    
    [addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    [addBtn addTarget:self action:@selector(addBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
}

-(void)addBtnDidClick
{
    self.addBtnBlock();
}

@end





